var echarts_echart_total = null;
var saveEchartObj = null;
var qysdata1 = null;
var qysdata2 = null;
var qysdata3 = null;
var qysdata4 = null;
var qysdata5 = null;
var qysdata6 = null;
var baseOption = {"tooltip": {"trigger": "axis"}, "legend": {"data": ["活跃", "解锁数"]}, "grid": {"left": "3%", "right": "4%", "bottom": "3%", "containLabel": true}, "xAxis": {"name": "日期", "type": "category", "boundaryGap": false, "data": ["2016/11/21", "2016/11/22", "2016/11/23", "2016/11/24", "2016/11/25", "2016/11/26", "2016/11/27"], "splitLine": false}, "yAxis": {"type": "value"}, "series": [{"name": "活跃", "type": "line", "data": [120, 132, 101, 134, 90, 230, 210]}, {"name": "解锁数", "type": "line", "data": [220, 182, 191, 234, 290, 330, 310]}]};
function getTotalData(startDate, endDate, type,limit) {
    //通过AJAX得到数据
    $.get(baseApiUrl + "?startdate=" + startDate + "&endDate=" + endDate + "&type=" + type + "&limit=" + limit, function(data) {
        if (data.code == 200) {
            //给本地的值赋值
            saveEchartObj = data.data;
            qysdata1 = data.data.data1;
            qysdata2 = data.data.data2;
            qysdata3 = data.data.data3;
            qysdata4 = data.data.data4;
            qysdata5 = data.data.data5;
            qysdata6 = data.data.data6;
            $("#remove_one").html('');
            $("#remove_one").append('<div  class="col-md-12" id="echart_total" style="height:400px;"></div>');
            echarts_echart_total = echarts.init(document.getElementById('echart_total'));
            newOption = baseOption;
            newOption.legend.data = data.data.data1.name;
            newOption.xAxis.data = data.data.xaxiadata;
            newOption.series = data.data.data1.series;
            echarts_echart_total.setOption(newOption);
            echarts_echart_total.resize();
        } else {
            alert(data.message);
        }
    });
}
function fitRandDate(str) {
    var startTime=$("#qys_startTime").val();
    var endTime=$("#qys_endTime").val();
    getTotalData(startTime,endTime,str,"");
}
$(".qys_ch_click").on('click', function() {
    var thisSelect = $(this).attr('tval');
    var legendData = null;
    var xAxisData = null;
    var seriesData = null;
    $("#remove_one").html('');
    $("#remove_one").append('<div  class="col-md-12" id="echart_total" style="height:400px;"></div>');
    echarts_echart_total = echarts.init(document.getElementById('echart_total'));
    switch (thisSelect) {
        case '1':
            legendData = qysdata1.name;
            xAxisData = saveEchartObj.xaxiadata;
            seriesData = qysdata1.series;
            break;
        case '2':
            legendData = qysdata2.name;
            xAxisData = saveEchartObj.xaxiadata;
            seriesData = qysdata2.series;
            break;
        case '3':
            legendData = qysdata3.name;
            xAxisData = saveEchartObj.xaxiadata;
            seriesData = qysdata3.series;
            break;
        case '4':
            legendData = qysdata4.name;
            xAxisData = saveEchartObj.xaxiadata;
            seriesData = qysdata4.series;
            break;
        case '5':
            legendData = qysdata5.name;
            xAxisData = saveEchartObj.xaxiadata;
            seriesData = qysdata5.series;
            break;
        case '6':
            legendData = qysdata6.name;
            xAxisData = saveEchartObj.xaxiadata;
            seriesData = qysdata6.series;
            break;
        default:
            legendData = qysdata1.name;
            xAxisData = saveEchartObj.xaxiadata;
            seriesData = qysdata1.series;
    }

    echarts_echart_total.setOption(option = {
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: legendData,
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: [
            {
                name: '日期',
                type: 'category',
                boundaryGap: false,
                splitLine: false,
                data: xAxisData,
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: seriesData
    });
    echarts_echart_total.resize();
});
$(window).resize(function() {
    if (echarts_echart_total != null) {
        echarts_echart_total.resize();
    }
});